home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MPW_TOOL / TOOLS / TOOLS_WI / PERL / UNIX / MAKEDEPE.SH < prev    next >
Text File  |  1992-01-04  |  4KB  |  163 lines

  1. case $CONFIG in
  2. '')
  3.     if test ! -f config.sh; then
  4.     ln ../config.sh . || \
  5.     ln ../../config.sh . || \
  6.     ln ../../../config.sh . || \
  7.     (echo "Can't find config.sh."; exit 1)
  8.     fi 2>/dev/null
  9.     . ./config.sh
  10.     ;;
  11. esac
  12. case "$0" in
  13. */*) cd `expr X$0 : 'X\(.*\)/'` ;;
  14. esac
  15. echo "Extracting makedepend (with variable substitutions)"
  16. $spitshell >makedepend <<!GROK!THIS!
  17. $startsh
  18. # $RCSfile: makedepend.SH,v $$Revision: 4.0.1.3 $$Date: 91/11/05 17:56:33 $
  19. #
  20. # $Log:    makedepend.SH,v $
  21. # Revision 4.0.1.3  91/11/05  17:56:33  lwall
  22. # patch11: various portability fixes
  23. # Revision 4.0.1.2  91/06/07  15:40:06  lwall
  24. # patch4: fixed cppstdin to run in the right directory
  25. # Revision 4.0.1.1  91/06/07  11:20:06  lwall
  26. # patch4: Makefile is no longer self-modifying code under makedepend
  27. # Revision 4.0  91/03/20  01:27:04  lwall
  28. # 4.0 baseline.
  29.  
  30. export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh \$0; kill \$\$)
  31.  
  32. cat='$cat'
  33. cppflags='$cppflags'
  34. cp='$cp'
  35. cppstdin='$cppstdin'
  36. cppminus='$cppminus'
  37. echo='$echo'
  38. egrep='$egrep'
  39. expr='$expr'
  40. mv='$mv'
  41. rm='$rm'
  42. sed='$sed'
  43. sort='$sort'
  44. test='$test'
  45. tr='$tr'
  46. uniq='$uniq'
  47. !GROK!THIS!
  48.  
  49. $spitshell >>makedepend <<'!NO!SUBS!'
  50.  
  51. $cat /dev/null >.deptmp
  52. $rm -f *.c.c c/*.c.c
  53. if test -f Makefile; then
  54.     cp Makefile makefile
  55. fi
  56. mf=makefile
  57. if test -f $mf; then
  58.     defrule=`<$mf sed -n        \
  59.     -e '/^\.c\.o:.*;/{'        \
  60.     -e    's/\$\*\.c//'        \
  61.     -e    's/^[^;]*;[     ]*//p'    \
  62.     -e    q                \
  63.     -e '}'                \
  64.     -e '/^\.c\.o: *$/{'        \
  65.     -e    N                \
  66.     -e    's/\$\*\.c//'        \
  67.     -e    's/^.*\n[     ]*//p'        \
  68.     -e    q                \
  69.     -e '}'`
  70. fi
  71. case "$defrule" in
  72. '') defrule='$(CC) -c $(CFLAGS)' ;;
  73. esac
  74.  
  75. make clist || ($echo "Searching for .c files..."; \
  76.     $echo *.c | $tr ' ' '\012' | $egrep -v '\*' >.clist)
  77. for file in `$cat .clist`; do
  78. # for file in `cat /dev/null`; do
  79.     case "$file" in
  80.     *.c) filebase=`basename $file .c` ;;
  81.     *.y) filebase=`basename $file .c` ;;
  82.     esac
  83.     $echo "Finding dependencies for $filebase.o."
  84.     $sed -n <$file >$file.c \
  85.     -e "/^${filebase}_init(/q" \
  86.     -e '/^#/{' \
  87.     -e 's|/\*.*$||' \
  88.     -e 's|\\$||' \
  89.     -e p \
  90.     -e '}'
  91.     $cppstdin -I/usr/local/include -I. $cppflags $cppminus <$file.c | sed -e 's#\.[0-9][0-9]*\.c#'"$file.c#" | \
  92.     $sed \
  93.     -e 's/^[     ]*#[     ]*line/#/' \
  94.     -e '/^# *[0-9][0-9]* *"/!d' \
  95.     -e 's/^.*"\(.*\)".*$/'$filebase'.o: \1/' \
  96.     -e 's|: \./|: |' \
  97.     -e 's|\.c\.c|.c|' | \
  98.     $uniq | $sort | $uniq >> .deptmp
  99. done
  100.  
  101. $sed <$mf >$mf.new -e '1,/^# AUTOMATICALLY/!d'
  102.  
  103. make shlist || ($echo "Searching for .SH files..."; \
  104.     $echo *.SH | $tr ' ' '\012' | $egrep -v '\*' >.shlist)
  105. if $test -s .deptmp; then
  106.     for file in `cat .shlist`; do
  107.     $echo `$expr X$file : 'X\(.*\).SH'`: $file config.sh \; \
  108.         /bin/sh $file >> .deptmp
  109.     done
  110.     $echo "Updating $mf..."
  111.     $echo "# If this runs make out of memory, delete /usr/include lines." \
  112.     >> $mf.new
  113.     $sed 's|^\(.*\.o:\) *\(.*/.*\.c\) *$|\1 \2; '"$defrule \2|" .deptmp \
  114.        >>$mf.new
  115. else
  116.     make hlist || ($echo "Searching for .h files..."; \
  117.     $echo *.h | $tr ' ' '\012' | $egrep -v '\*' >.hlist)
  118.     $echo "You don't seem to have a proper C preprocessor.  Using grep instead."
  119.     $egrep '^#include ' `cat .clist` `cat .hlist`  >.deptmp
  120.     $echo "Updating $mf..."
  121.     <.clist $sed -n                            \
  122.     -e '/\//{'                            \
  123.     -e   's|^\(.*\)/\(.*\)\.c|\2.o: \1/\2.c; '"$defrule \1/\2.c|p"    \
  124.     -e   d                                \
  125.     -e '}'                                \
  126.     -e 's|^\(.*\)\.c|\1.o: \1.c|p' >> $mf.new
  127.     <.hlist $sed -n 's|\(.*/\)\(.*\)|s= \2= \1\2=|p' >.hsed
  128.     <.deptmp $sed -n 's|c:#include "\(.*\)".*$|o: \1|p' | \
  129.        $sed 's|^[^;]*/||' | \
  130.        $sed -f .hsed >> $mf.new
  131.     <.deptmp $sed -n 's|c:#include <\(.*\)>.*$|o: /usr/include/\1|p' \
  132.        >> $mf.new
  133.     <.deptmp $sed -n 's|h:#include "\(.*\)".*$|h: \1|p' | \
  134.        $sed -f .hsed >> $mf.new
  135.     <.deptmp $sed -n 's|h:#include <\(.*\)>.*$|h: /usr/include/\1|p' \
  136.        >> $mf.new
  137.     for file in `$cat .shlist`; do
  138.     $echo `$expr X$file : 'X\(.*\).SH'`: $file config.sh \; \
  139.         /bin/sh $file >> $mf.new
  140.     done
  141. fi
  142. $rm -f $mf.old
  143. $cp $mf $mf.old
  144. $cp $mf.new $mf
  145. $rm $mf.new
  146. $echo "# WARNING: Put nothing here or make depend will gobble it up!" >> $mf
  147. $rm -f .deptmp `sed 's/\.c/.c.c/' .clist` .shlist .clist .hlist .hsed
  148.  
  149. !NO!SUBS!
  150. $eunicefix makedepend
  151. chmod +x makedepend
  152. case `pwd` in
  153. *SH)
  154.     $rm -f ../makedepend
  155.     ln makedepend ../makedepend
  156.     ;;
  157. esac
  158.